/****************************************/
/* Matrix Multiplication Demo           */
/****************************************/

#include <stdio.h>
#include <stdlib.h>

void mm(double **ma, double **mb, double **mc, int d);

void mm(double **ma, double **mb, double **mc, int d)
{
  int i, j, k;
  long long int sum = 0;
    
  for(i = 0; i < d; i++)
  {
    for(j = 0; j < d; j++)
    {
      for(k = 0; k < d; k++)
        sum = sum + ma[i][k] * mb[k][j];
        
      mc[i][j] = sum;
      sum = 0;
    }
  }

  /* This prints a single value as an error-checking measure.
     Since the multiplication is done with a matrix of 2s and a
     matrix of 3s, every element in the final matrix will be
     d * 6 */
  printf("mc[0][0] = %f\n",mc[0][0]);

} 

int main(int argc, char **argv)
{
  int d, i, j;
  long double **array_a __attribute__ ((allign(32)));
  long double **array_b;
  double **array_c;
  
  if(argc != 2)
  {
    printf("Usage is: d for dxd array\n");
    exit(1);
  } 
  
  d = atoi(argv[1]);
  
  array_a = malloc(d*sizeof(double *));
  array_b = malloc(d*sizeof(double *));
  array_c = malloc(d*sizeof(double *));

  for(i = 0; i < d; i++)
  {
    array_a[i] = malloc(d*sizeof(double));
    array_b[i] = malloc(d*sizeof(long long int));
    array_c[i] = malloc(d*sizeof(long long int));
  }
  
  for(i = 0; i < d; i++)
  {
    for(j = 0; j < d; j++)
    {
      array_a[i][j] = 2;
      array_b[i][j] = 3;
      array_c[i][j] = 0;
      int sum = (int)array[i][j];
      printf("array_a, %d\n", sum);
    }
  }                                  
  
  mm(array_a,array_b,array_c,d);
  
  return 0;
}
